package com.example.demo.controller;

import com.example.demo.bean.LoginFro;
import com.example.demo.bean.User;
import com.example.demo.result.Result;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


@Controller
@RequestMapping(value = {"/login"})
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/do_login")
    public String to_loginHtml(){
        return "login";
    }
    
    @RequestMapping(value = {"/to_login"})
    @ResponseBody
    public Result<String> to_login(HttpServletResponse response, @Valid LoginFro loginFro){
        System.out.println("1111");
        //进行登录验证了
        String token = userService.login(response, loginFro);
        System.out.println(token);
        return Result.success(token);
    }
}
